<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>开启头部工具栏 - 数据表格</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/back/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/back/style/admin.css" media="all">
</head>
<body>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">主页</a>
      <a><cite>组件</cite></a>
      <a><cite>数据表格</cite></a>
      <a><cite>开启头部工具栏</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">回帖</div>
          <div class="layui-card-body">
          	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline layuiadmin-input-useradmin">
            <label class="layui-form-label">回帖人</label>
            <div class="layui-input-block">
              <input type="text" name="replyer" id="userName" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">回帖内容</label>
            <div class="layui-input-block">
              <input type="text" name="content" id="com2Text" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" id="fuzzyQuery">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>
      
            <table class="layui-hide" id="test-table-toolbar" lay-filter="test-table-toolbar"></table>
            
            <script type="text/html" id="test-table-toolbar-toolbarDemo">
              <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
              </div>
            </script>
            <script type="text/html" id="test-table-toolbar-barDemo">
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="${pageContext.request.contextPath }/back/layui/layui.js"></script>
  <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
  <script>
    function renderdata(userName,com2Text){
  layui.config({
    base: '${pageContext.request.contextPath }/back/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var admin = layui.admin
    ,table = layui.table;
  
    table.render({
      elem: '#test-table-toolbar'
      ,url: '${pageContext.request.contextPath }/comments/allCom2?userName='+userName+'&com2Text='+com2Text
      ,toolbar: '#test-table-toolbar-toolbarDemo'
      ,title: '回帖'
      ,cols: [[
        {
				type: "checkbox",
				fixed: "left"
			}, {
				field: "com2Id",
				width: 100,
				title: "ID",
				sort: !0
			}, {
                templet: "<div>{{d.user.userName}}</div>",
				field: "replyer",
				title: "回帖人"
			}, {
                templet: "<div>{{d.comments.comId}}</div>",
				field: "cardid",
				title: "回帖ID",
				sort: !0
			}, {
                templet: "<div>{{d.user.userImg}}</div>",
				field: "avatar",
				title: "头像",
				width: 100,
				templet: "#imgTpl"
			}, {
				field: "com2Text",
				title: "回帖内容",
				width: 200
			}, {
				field: "com2Date",
				title: "回帖时间",
				sort: !0
			}, {
				title: "操作",
				width: 150,
				align: "center",
				fixed: "right",
				toolbar: "#test-table-toolbar-barDemo"
			}
      ]]
      ,page: true
      ,limit:10
    });
    
    //头工具栏事件
    table.on('toolbar(test-table-toolbar)', function(obj){
      var checkStatus = table.checkStatus(obj.config.id);
      switch(obj.event){
        case 'getCheckData':
          var data = checkStatus.data;
          layer.alert(JSON.stringify(data));
        break;
        case 'getCheckLength':
          var data = checkStatus.data;
          layer.msg('选中了：'+ data.length + ' 个');
        break;
        case 'isAll':
          layer.msg(checkStatus.isAll ? '全选': '未全选');
        break;
      };
    });
    
    //监听行工具事件
    table.on('tool(test-table-toolbar)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
        layer.confirm('真的删除行么', function(index){
          $.get("${pageContext.request.contextPath}/comments/delCom2",{com2Id:data.com2Id},
                  function(){
                    layer.msg("删除成功")
                  },"json")
          obj.del();
          layer.close(index);
        });
      }
    });
  
  });
    }
    $(function() {
      //渲染数据
      renderdata("","","");
      //模糊查询
      $("#fuzzyQuery").click(function(){
        var userName=$("#userName").val();
        var com2Text=$("#com2Text").val();
        renderdata(userName,com2Text);
      })
    })
  </script>
</body>
</html>